<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('入库单详情')"/>
    <style>
        [v-cloak] {
            display: none
        }
    </style>
</head>
<body>
<div class="container-div">
    <div style="width: 100%;height: 50px">
        <el-button style="float: right" type="info" @click="closeModal()">返回</el-button>
    </div>

    <el-row class="deer-panel">
        <span style="color: #409EFF">入库单信息</span>
        <el-divider style="margin-top: 10px"></el-divider>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">单据号：</div>
                <div class="deer-value" v-cloak>{{billInMaster.billNo}}</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">操作人员：</div>
                <div class="deer-value" v-cloak>{{billInMaster.createUserName}}</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">操作时间：</div>
                <div class="deer-value" v-cloak>{{billInMaster.createTime}}</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">入库类型：</div>
                <div class="deer-value" v-for="(item, index) in inTypes" :key="index" v-if="billInMaster.type == item.dictValue" v-cloak>{{item.dictLabel}}</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">仓库：</div>
                <div class="deer-value" v-cloak>{{billInMaster.wareName}}</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">状态：</div>
                <div class="deer-value" v-if="billInMaster.state === 1">未审核</div>
                <div class="deer-value" v-if="billInMaster.state === 2">审核通过</div>
                <div class="deer-value" v-if="billInMaster.state === 3">正在入库</div>
                <div class="deer-value" v-if="billInMaster.state === 4">入库完成</div>
            </div>
        </el-col>
        <el-col :span="6">
            <div class="deer-ky">
                <div class="deer-key">备注：</div>
                <div class="deer-value" v-cloak>{{billInMaster.memo}}</div>
            </div>
        </el-col>
    </el-row>

    <el-row :gutter="20">
        <el-col :span="24">
            <el-tabs type="border-card" class="deer-panel" style="margin-top: 15px;padding-top: 0px">
                <el-tab-pane>
                    <span slot="label"><i class="el-icon-date"></i> 物料详情</span>
                    <el-table :data="item.list" border>
                        <el-table-column fixed prop="itemId" label="ID" align="center" v-if="false"></el-table-column>
                        <el-table-column fixed prop="itemCode" label="物料编码" align="center"></el-table-column>
                        <el-table-column fixed prop="itemName" label="物料名称" align="center"></el-table-column>
                        <el-table-column fixed prop="model" label="型号" align="center" v-if="false"></el-table-column>
                        <el-table-column fixed prop="pdTime" label="生产日期" align="center"></el-table-column>
                        <el-table-column fixed prop="batch" label="批次" align="center"></el-table-column>
                        <el-table-column fixed prop="areaQuantity" label="暂存区数量" align="center" v-if="billInMaster.type == 2"></el-table-column>
                        <el-table-column fixed prop="quantity" label="计划总数" align="center"></el-table-column>
                        <el-table-column fixed prop="distributionNum" label="行号" align="center" v-if="billInMaster.type != 2"></el-table-column>
                        <el-table-column fixed prop="benCiRuKu" label="本次入库" align="center" v-if="billInMaster.type != 2"></el-table-column>
                    </el-table>
                    <el-pagination
                            @current-change="chengCurrentPage"
                            :current-page="item.currentPage"
                            :page-size="item.pageSize"
                            layout="prev, pager, next"
                            :total="item.total">
                    </el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-col>
    </el-row>
</div>

<div th:include="include::footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('in:billInMaster:edit')}]];
    var removeFlag = [[${@permission.hasPermi('in:billInMaster:remove')}]];
    var prefix = ctx + "in/billInMaster";
    var detailPrefix = ctx + "in/billInDetail";

    var billId = parseInt(localStorage.getItem(prefix+'/detail'));
    var vue = new Vue({
        el: '.container-div',
        data: {
            billInMaster: [],
            inTypes: [],
            item: {
                currentPage: 1,
                pageSize: 5,
                total: '',
                list: []
            },
        },
        methods: {
            closeModal: function(){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },

            getInTypes: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    url: '/system/dict/data/list',
                    type: 'POST',
                    data: {
                        dictType: 'put_goods_type'
                    },
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.inTypes = data.rows;
                    }
                })
            },

            getBillInMaster: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: prefix + '/findBillInMasterById',
                    data: {
                        billId: billId
                    },
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        data.createTime = data.createTime.slice(0, 19);
                        that.billInMaster = data;
                    }
                });
            },

            chengCurrentPage: function(currentPage){
                this.item.currentPage = currentPage;
                this.getBillDetails(null);
            },

            getBillDetails: function(){
                var that = this;
                $.ajax({
                    url: detailPrefix + "/findBillInDetailListByBillId",
                    type: "POST",
                    data: {
                        billId: billId,
                        pageSize: that.item.pageSize,
                        pageNum: that.item.currentPage
                    },
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        var msg = data.rows;
                        for(var i = 0; i < msg.length; i++){
                            if(msg[i].pdTime!=null) {
                                msg[i].pdTime = msg[i].pdTime.slice(0, 10);
                            }
                        }
                        that.item.list = msg;
                        that.item.total = data.total;
                    }
                })
            }
        },
        created(){
            this.getInTypes();
            this.getBillInMaster();
            this.getBillDetails();
        }
    })
</script>
</body>
</html>
